package xyz.xtt.admin.config;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import xyz.xtt.admin.interceptors.LoginInterceptor;

@Configuration
public class WebConfig implements WebMvcConfigurer {
	@Autowired
	private LoginInterceptor loginInterceptor;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry
				.addInterceptor(loginInterceptor)
				.excludePathPatterns("/api/admin/admin_user/login")
				.excludePathPatterns(Arrays.asList("/css/**", "/js/**", "/images/**", "/webjars/**", "/favicon.ico", "/v3/api-docs/**", "/doc.html"));
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// 配置Swagger2的静态资源处理
		registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
	}
}
